import scipy.fftpack as fftpack

# 指定FFT变换的点数
num_samples = 512

# 实数FFT
print('\nreal number fft:')
x = []
for i in range(num_samples//2):
    x.append(1)
    x.append(2)
X = fftpack.rfft(x) # 使用rfft对实数序列变换
for i in range(len(X)):
    print("%3d: %r"%(i, X[i]))
X = fftpack.fft(x)  # 使用fft对实数序列变换
for i in range(len(X)):
    print("%3d: %r"%(i, X[i]))

# 复数FFT
print('\ncomplex number fft:')
x = []
for i in range(num_samples//2):
    x.append(1+0j)
    x.append(2+0j)
X = fftpack.fft(x)
for i in range(len(X)):
    print("%3d: %r"%(i, X[i]))

# FFT逆变换
print('\ninverse fft:')
x = fftpack.ifft(X)
for i in range(len(x)):
    print("%3d: %r"%(i, x[i]))

